import { defineStore } from 'pinia';
import service from '../utils/request';

/**
 * 用户信息
 * @methods setUserInfos 设置用户信息
 */
export const useUserInfo = defineStore('userInfo', {
	state: (): UserInfosState => ({
		userInfos: {
			code: '',
			name: '',
			avatar: '',
			roleName: '',
			redirectURL: '',
			themeConfig: {},
			authBtnList: [],
			authMenuList: [],
			dataScope: []
		},
	}),
	actions: {
		async setUserInfos() {
			// 存储用户信息到浏览器缓存
			// if (Session.get('userInfo')) {
			// 	this.userInfos = Session.get('userInfo');
			// } else {
				
			const { content } = await this.getApiUserInfo();
			this.userInfos = content;
			console.log(this.userInfos.name)
			// }
		},
		// 模拟接口数据
		async getApiUserInfo() {
			return service({
				url: 'v0/system/auth/userinfo',
				method: 'get',
			})
		},
	},
});
